import 'package:inmotion_pro/l10n/local.dart';
import 'package:inmotion_pro/pages/models/vehicle_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:lx_widgets_library/lx_widgets_library.dart';

/// 我的车辆信息视图
class MineVehicleInfoView extends StatelessWidget {
  // 车辆列表
  final List<VehicleModel> vehicleModelList;
  // 是否登录
  final bool isLogin;
  // 点击事件
  final Function()? onTap;

  const MineVehicleInfoView({
    super.key,
    required this.vehicleModelList,
    this.isLogin = false,
    this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    double radius = 12.w;
    return ClipRRect(
      borderRadius: BorderRadius.circular(radius),
      child: GestureDetector(
        onTap: () {
          if (onTap != null) {
            onTap!();
          }
        },
        child: Container(
          padding: EdgeInsets.only(
            left: CONTENT_MARGIN,
            right: CONTENT_MARGIN,
            top: CONTENT_MARGIN / 2,
            bottom: CONTENT_MARGIN / 2,
          ),
          decoration: BoxDecoration(
            gradient:
                isLogin ? _buildLoggedInGradient() : _buildLoggedOutGradient(),
          ),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  LxText(
                    local.my_vehicles,
                    color: Colors.white,
                    fontWeightEnum: LxFontWeightEnum.titleMedium,
                  ),
                  SizedBox(height: CONTENT_MARGIN),
                  LxText(
                    "${vehicleModelList.length}",
                    color: Colors.white,
                    fontWeightEnum: LxFontWeightEnum.titleExtraLarge,
                  ),
                ],
              ),
              _buildArrowIndicator(),
            ],
          ),
        ),
      ),
    );
  }

  LinearGradient _buildLoggedInGradient() {
    return LinearGradient(
      begin: Alignment.topLeft,
      end: Alignment.bottomRight,
      colors: [
        const Color(0xFFFF6600).withOpacity(0.7),
        const Color(0xFFFF8C00).withOpacity(0.7),
        const Color(0xFFFFA500).withOpacity(0.7),
      ],
      stops: const [0.0, 0.6, 1.0],
    );
  }

  LinearGradient _buildLoggedOutGradient() {
    return LinearGradient(
      begin: Alignment.topLeft,
      end: Alignment.bottomRight,
      colors: [
        Colors.grey.shade600,
        Colors.grey.shade500,
        Colors.grey.shade400,
      ],
    );
  }

  // 箭头指示器
  Widget _buildArrowIndicator() {
    return Container(
      width: 34.w,
      height: 34.w,
      decoration: BoxDecoration(
        color: Colors.white.withOpacity(0.2),
        shape: BoxShape.circle,
        border: Border.all(
          color: Colors.white.withOpacity(0.4),
          width: 2,
        ),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.1),
            blurRadius: 8,
            offset: const Offset(0, 2),
          ),
        ],
      ),
      child: Icon(
        Icons.arrow_forward_ios_rounded,
        color: Colors.white,
        size: 18.w,
      ),
    );
  }
}
